<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
</head>
<style>
    .none_tip {
        color: #565656;
        font-size: 0.7rem;
        margin: 10rem auto;
        text-align: center;
    }

    .bottom_div {
        width: 100%;
        height: 6.5rem;
        background-color: #fff;
        position: fixed;
        bottom: 0;
        left: 0;
    }

    .bottom_div .img_item {
        width: 25%;
        display: inline-block;
        margin-left: -0.25rem;
        height: 2rem;
        text-align: center;
        color: #565656;
        font-size: 0.6rem;
        /* margin-top: 0.5rem; */
    }


    .bottom_div .img_item img {
        width: 1rem;
        height: 1rem;
        margin: 0.5rem 0 0.5rem 0;
    }

    .bottom_div .input {
        padding: 0 1rem;
        position: relative;
    }

    .bottom_div .input input {
        margin-top: 1.5rem;
        width: 95%;
        padding-left: 5%;
        height: 2.5rem;
        background-color: #999;
        font-size: 0.8rem;
        color: #fff;
        border-radius: 0.5rem;
        outline: none;
    }

    .bottom_div .input input::-webkit-input-placeholder {
        color: #fff;
    }

    .bottom_div .input button {
        outline: none;
        position: absolute;
        width: 4rem;
        height: 2rem;
        background-color: #2780e8;
        font-size: 0.7rem;
        color: #fff;
        border-radius: 0.5rem;
        right: 1rem;
        bottom: 0;
    }

    .yaocai_div {
        padding: 0 0.8rem;
    }

    .yaocai_total {
        text-align: center;
        /* background-color: #2780e8; */
        color: #2780e8;
        height: 1rem;
        line-height: 1rem;
        width: 100%;
        font-size: 0.7rem;
        margin-bottom: 0.5rem;
    }

    .yaocai_div .yaocai_div_item {
        width: 8.45rem;
        height: 2rem;
        display: inline-block;
        border: 1px solid #E8E8E8;
        border-top: none;
        position: relative;
    }

    .yaocai_div .yaocai_div_item img {
        width: 0.8rem;
        height: 0.8rem;
        position: absolute;
        top: 0.6rem;
        left: 0.5rem;
    }

    .yaocai_div .yaocai_div_item .yaocai_name {
        font-size: 0.7rem;
        color: #565656;
        position: absolute;
        top: 0.45rem;
        left: 1.7rem;
    }

    .yaocai_div .yaocai_div_item .yaocai_num {
        position: absolute;
        width: 2.7rem;
        height: 1rem;
        line-height: 1rem;
        top: 0.5rem;
        right: 0.5rem;
        color: #565656;
        font-size: 0.7rem;
    }

    .yaocai_div .yaocai_div_item .yaocai_num input {
        border-bottom: 1px solid #E8E8E8;
        width: 1.5rem;
        height: 100%;
        outline: none;
        margin-right: 0.3rem;
        text-align: center;
        color: #565656;
        font-size: 0.7rem;
    }

    .yaocai_div .yaocai_div_item:nth-child(1),
    .yaocai_div .yaocai_div_item:nth-child(2) {
        border-top: 1px solid #E8E8E8;
    }

    .yaocai_div .yaocai_div_item:nth-child(2n) {
        margin-left: -0.25rem;
        border-left: none;
    }

    .yaocai_div .tips {
        font-size: 0.6rem;
        text-align: center;
        height: 2rem;
        line-height: 2rem;
    }

    .add_num_zhezhao,
    .lack_yaocai_zhezhao,
    .special_yaocai_zhezhao {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.7);
        z-index: 10;
    }

    .special_yaocai_zhezhao_ming {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 10;
        background-color: rgba(0, 0, 0, 0.7);
    }

    .add_num_zhezhao .add_num_main {
        width: 13rem;
        margin: 10rem 0 0 3rem;
        background-color: #fff;
        text-align: center;
        border-radius: 1rem;
    }

    .add_num_zhezhao .add_num_main .add_num_title {
        padding: 1.2rem 0 0.4rem 0;
        color: #565656;
        font-size: 0.8rem;
    }

    .add_num_zhezhao .add_num_main .add_num_subtitle {
        color: #565656;
        font-size: 0.6rem;
        padding: 0.4rem 0 1rem 0;
    }

    .add_num_zhezhao .add_num_main .jiliang {
        padding: 0 2rem;
    }

    .add_num_zhezhao .add_num_main .jiliang p {
        width: 100%;
        height: 1.7rem;
        line-height: 1.7rem;
        font-size: 0.7rem;
        text-align: left;
        padding-bottom: 0.5rem;
    }

    .add_num_zhezhao .add_num_main .jiliang p span {
        float: right;
    }

    .add_num_zhezhao .add_num_main .jiliang p span img {
        width: 0.7rem;
        height: 0.7rem;
    }

    .add_num_zhezhao .add_num_main .jiliang p span input {
        width: 2rem;
        height: 1rem;
        border-bottom: 1px solid #565656;
        text-align: center;
        outline: none;
    }

    .add_num_zhezhao .btn_div {
        height: 2rem;
        line-height: 2rem;
        font-size: 0.7rem;
        border-top: 1px solid #E8E8E8;
    }

    .add_num_zhezhao .btn_div div {
        width: 50%;
        display: inline-block;
        text-align: center;
        margin-top: -0.1rem;
    }

    .add_num_zhezhao .btn_div div:last-child {
        color: #2780e8;
        margin-left: -0.25rem;
        border-left: 1px solid #E8E8E8;
    }

    .lack_yaocai_zhezhao .lack_yaocai_main {
        width: 16.25rem;
        margin: 10rem 0 0 1.25rem;
        background-color: #fff;
        height: 10rem;
    }

    .lack_yaocai_zhezhao .lack_yaocai_main .lack_title {
        padding: 1rem 0 0.5rem 1rem;
        color: #565656;
        font-size: 0.8rem;
        font-weight: bold;
        font-family: PingFangSC;
    }

    .lack_yaocai_zhezhao .lack_yaocai_main .lack_main {
        padding: 0 1rem;
        color: #838383;
        font-size: 0.7rem;
        line-height: 1rem;
    }

    .lack_yaocai_zhezhao .lack_yaocai_main .lack_yaocai {
        padding: 1rem 0 1.5rem 1rem;
        color: #838383;
        font-size: 0.7rem;
    }

    .lack_yaocai_zhezhao .lack_yaocai_main .lack_yaocai span {
        color: #2780e8;
    }

    .lack_yaocai_zhezhao .lack_yaocai_main .btn_div span {
        float: right;
        padding: 0 1rem 0rem 1rem;
        color: #565656;
        font-size: 0.7rem;
    }

    .lack_yaocai_zhezhao .lack_yaocai_main .btn_div span:last-child {
        color: #838383;
    }

    .special_yaocai_main {
        width: 16.25rem;
        margin: 10rem 0 0 1.25rem;
        background-color: #fff;
    }

    .special_yaocai_main_fanan {
        width: 16.25rem;
        height: 7rem;
        margin: 10rem 0 0 1.25rem;
        background-color: #fff;
        font-size: 16px;
        padding: 2rem 0;
    }

    .special_yaocai_main .special_yaocai_title {
        padding: 1rem 0 0 1rem;
        color: #565656;
        font-size: 0.8rem;
        font-family: PingFangSC;
        font-weight: bold;
    }

    .special_yaocai_main .special_yaocai_tip {
        padding: 0.5rem 0 0.3rem 1rem;
        color: #838383;
        font-size: 0.7rem;
    }

    .special_yaocai_main .special_yaocai {
        color: #2780e8;
        font-size: 0.7rem;
        padding: 0rem 0 1rem 1rem;
    }

    .special_yaocai_main .checked_div {
        height: 2rem;
        position: relative;
        font-size: 0.7rem;
        color: #838383;
    }

    .special_yaocai_main .checked_div img {
        position: absolute;
        width: 1rem;
        height: 1rem;
        top: 0.5rem;
        left: 1rem;
    }

    .special_yaocai_main .checked_div .checked_div_title {
        position: absolute;
        left: 2.5rem;
        top: 0;
    }

    .special_yaocai_main .checked_div .checked_div_subtitle {
        font-size: 0.6rem;
        color: #2780e8;
        position: absolute;
        bottom: 0;
        left: 2.5rem;
    }

    .special_yaocai_main .btn_div {
        height: 2.7rem;
    }

    .special_yaocai_main .btn_div span {
        float: right;
        padding: 1rem;
        font-size: 0.7rem;
    }

    .special_yaocai_main .btn_div span:first-child {
        color: #838383;
    }

    .searchReslut {
        width: 100%;
        position: absolute;
        top: -3rem;
        display: -webkit-box;
        overflow-x: scroll;
        -webkit-overflow-scrolling: touch;
    }

    .searchReslut .item {
        box-sizing: border-box;
        background-color: #fff;
        /* line-height: 1.5rem; */
        height: 3rem;
        width: 25%;
        font-size: 0.7rem;
        border: 1px solid #e8e8e8;
        border-left: none;
        text-align: center;
    }

    .searchReslut .item p {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        margin-top: 0.4rem;
    }

    .searchReslut .item .item_price {
        color: #2780e8;
        font-size: 0.6rem;
    }

    .price_zhezhao {
        width: 100%;
        height: 100%;
        position: fixed;
        top: 0;
        left: 0;
        background-color: rgba(0, 0, 0, 0.7);
    }

    .price_zhezhao .price_zhezhao_main {
        width: 16.25rem;
        margin-left: 1.25rem;
        margin-top: 7.5rem;
        background-color: #fff;
    }

    .price_zhezhao .price_zhezhao_main .price_title {
        padding: 1rem 0 1rem 1rem;
        color: #565656;
        font-size: 0.8rem;
    }

    .price_zhezhao .price_zhezhao_main .price_div {
        padding: 0 1rem;
        overflow-y: auto;
        max-height: 11rem;
        min-height: 4rem;
    }

    .price_zhezhao .price_zhezhao_main .price_div .price_div_item {
        line-height: 2rem;
        color: #565656;
        font-size: 0.7rem;
    }

    .price_zhezhao .price_zhezhao_main .price_div .price_div_item span {
        color: #2780e8;
    }

    .price_zhezhao .price_zhezhao_main .price_div input {
        line-height: 2rem;
        color: #565656;
        font-size: 0.7rem;
        outline: none;
        border-bottom: none;
    }

    .price_zhezhao .price_zhezhao_main .btn_div {
        width: 100%;
        height: 3rem;
        line-height: 3rem;
    }

    .price_zhezhao .price_zhezhao_main .btn_div span {
        width: 49%;
        display: inline-block;
        /* margin-left: -0.25rem; */
        text-align: center;
        color: #565656;
        font-size: 0.7rem;
    }

    .fanan_title {
        text-align: center;
        font-size: 20px;
        font-weight: 1000;
    }

    .fanan_input {
        display: flex;
        align-items: center;
        margin-left: 0.5rem;
        margin-top: 1rem;
    }

    .fanan_input_title {
        font-size: 18px;
    }

    .fanan_input_input {
        /* display: block; */
        margin-top: 0.1rem;
        margin-left: 0.3rem;
    }

    .fanan_button {
        display: flex;
        align-items: center;
        justify-content: center;
        margin-top: 2rem;
    }

    .fanan_quxiao {
        border-radius: 5px;
        width: 3rem;
        height: 1.5rem;
        background-color: blanchedalmond;
        font-size: 12px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .fanan_queding {
        border-radius: 5px;
        width: 3rem;
        height: 1.5rem;
        background-color: red;
        color: white;
        font-size: 12px;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-left: 0.4rem;
    }
</style>

<body>
    <div id="app" v-cloak>
        <div class="placeholder_div"></div>
        <p class="yaocai_total">{{noticeTip}}</p>
        <div class="yaocai_div">

            <div class="yaocai_div_item" v-for="(item,index) in allDrugs">
                <img src="../../image/icon_del.png" @click="delAllDrugs(index)" alt="">
                <p class="yaocai_name">{{item.name}}</p>
                <div class="yaocai_num">
                    <input type="number" v-model="item.quantity" @input="sendData()">{{item.unit}}
                </div>
            </div>

            <p class="tips">已经没有更多了~</p>
        </div>

        <div class="bottom_div">
            <div class="img_item" v-if="changeQuantityMask">
                <img src="../../image/icon_add_yaocai_3.png" alt="">
                <p>按倍改量</p>
            </div>
            <div class="img_item" @click="alwaysUsedMask">
                <img src="../../image/icon_add_yaocai_2.png" alt="">
                <p>存为常用方</p>
            </div>
            <div class="img_item openwin" data-win="../my_always_useing_win" data-index="11">
                <img src="../../image/icon_add_yaocai_1.png" alt="">
                <p>调用常用方</p>
            </div>

            <div class="img_item" @click="emptyDrugs()">
                <img src="../../image/icon_add_yaocai_4.png" alt="">
                <p>清空药材</p>
            </div>

            <div class="input">
                <!-- <button class="confirm" v-if="yaocai != ''" v-show="yaocai!=' '">确定</button> -->
                <input type="text" v-model="searchKey" onkeyup="this.value=this.value.replace(/\s+/g,'')"
                    placeholder="请输入药材名">
            </div>
            <div class="searchReslut">
                <div class="item" onclick="get_focus()" v-if="searchKey != ''" v-show="searchKey!=' '"
                    v-for="item in searchReslut"
                    @click="pushAllDrugs(item.name,item.drugsNo,item.salePrice,item.specs,item.storeId,item.drugsId)">
                    <p class="item_name">{{item.name}}</p>
                    <p class="item_price">￥{{item.salePrice}}元/g</p>
                </div>

            </div>
        </div>

        <div style="height: 7.5rem;width: 100%;"></div>
        <!-- 按倍改量弹出层 -->
        <div class="add_num_zhezhao" v-if="changeQuantityMask">
            <div class="add_num_main">
                <p class="add_num_title">按倍改量</p>
                <p class="add_num_subtitle">所有药材按倍改量后将四舍五入取整</p>

                <div class="jiliang">
                    <p class="now_jiliang">当前总剂量 <span>{{allDrugsNum}}g</span></p>
                    <p class="alter_jiliang">修改后总剂量 <span>{{(num * allDrugsNum).toFixed(0)}}g</span></p>
                    <p class="alter_num">修改倍速
                        <span>
                            <img src="../../image/icon_del1.png" @click="delNum" alt="">
                            <input type="number" readonly v-model="num">
                            <img src="../../image/icon_add.png" @click="addNum" alt="">
                        </span>
                    </p>
                </div>


                <div class="btn_div">
                    <div @click="changeQuantityMask = false">取消</div>
                    <div @click="changeQuantity">保存</div>
                </div>
            </div>
        </div>

        <!-- 缺药提示弹出层 -->
        <div class="lack_yaocai_zhezhao" v-if="lackDrugsMask">
            <div class="lack_yaocai_main">
                <p class="lack_title">缺药提示</p>
                <p class="lack_main">当前药房暂无法提供全部药材，您可修改药材或更换药房看看</p>
                <p class="lack_yaocai">药房缺药：<span>葛根</span></p>
                <div class="btn_div">
                    <span>更换药房</span>
                    <span>修改药材</span>
                </div>
            </div>
        </div>

        <!-- 特殊缺药签字确认弹出层 -->
        <div class="special_yaocai_zhezhao" v-if="specialDrugsMask">
            <div class="special_yaocai_main">
                <p class="special_yaocai_title">特殊药材签字确认</p>
                <p class="special_yaocai_tip">以下药材剂量已超过药典建议：</p>
                <p class="special_yaocai">葛根20g，葛根30g</p>
                <div class="checked_div">
                    <img @click="radio_cheched=radio_cheched?false:true"
                        :src="radio_cheched ? '../../image/icon_radio_checked.png': '../../image/icon_radio.png'"
                        alt="">
                    <p class="checked_div_title">我确认以上药材无需修改</p>
                    <p class="checked_div_subtitle">*勾选后即可按此开方</p>
                </div>

                <div class="btn_div">
                    <span onclick="submit()">确定开方</span>
                    <span>修改药材</span>
                </div>
            </div>
        </div>

        <!-- 保存药材遮罩 -->
        <div class="price_zhezhao" v-if="checkDrugsMask">
            <div class="price_zhezhao_main">
                <p class="price_title">确认药材</p>
                <div class="price_div">
                    <p class="price_div_item" v-for="item in allDrugs">
                        {{item.name}} <span>{{item.salePrice}}元/g 共{{item.quantity}}g</span>
                        总共{{toThreeDecimal(item.salePrice * item.quantity)}}元
                    </p>
                </div>

                <div class="btn_div">
                    <span @click="checkDrugsMask = false">取消</span>
                    <span style="color: #2E8EFF;" @click="saveDrugs()">确定</span>
                </div>
            </div>
        </div>

        <!-- 存为常用方 -->
        <div class="special_yaocai_zhezhao_ming" v-if="alwaysUsedPlanMask">
            <div class="special_yaocai_main_fanan">
                <div class="fanan_title">
                    <p>存为常用方</p>
                </div>
                <div class="fanan_input">
                    <p class="fanan_input_title">常用方名称</p>
                    <input placeholder="请输入常用方名称" v-model="title" class="fanan_input_input">
                </div>
                <div class="fanan_button">
                    <div @click="alwaysUsedPlanMask = false" class="fanan_quxiao">取消</div>
                    <div @click="saveAlwaysUsedPlan" class="fanan_queding">确定</div>
                </div>
            </div>
        </div>


    </div>
</body>

</html>
<script src="../../script/set_root.js"></script>

<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/hb.js"></script>
<script type="text/javascript" src="../../script/vue.js"></script>
<script type="text/javascript" src="../../script/zepto.min.js"></script>
<script type="text/javascript">
    apiready = function () {
        init();

        if (api.pageParam.allDrugs) {
            app.allDrugs = api.pageParam.allDrugs
            app.allDrugsNum = 0 // 每次计算数量时都需要先置空
            for (var i = 0; i < app.allDrugs.length; i++) {
                app.allDrugsNum += Number(app.allDrugs[i].quantity)
                app.drugMoney += (Number(app.allDrugs[i].quantity) * Number(app.allDrugs[i]
                    .salePrice))
            }
        } else {
            app.allDrugs = api.pageParam.allDrugs
        }
        api.addEventListener({
            name: 'alwaysUsedPlan'
        }, function (ret, err) {
            app.allDrugs = ret.value.value
            app.sendData()
        });
        api.addEventListener({
            name: 'checkDrugsMask'
        }, function (ret, err) {
            app.checkDrugs()
        });

        document.onkeydown = function (e) { // 回车提交表单
            // 兼容FF和IE和Opera
            var theEvent = window.event || e;
            var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
            if (code == 13) {
                $(".input input").focus()
            }
        }

    }

    function get_focus() {
        setTimeout(function () {
            $(".yaocai_div_item div input").eq(0).val("")
            setTimeout(function () {
                $(".yaocai_div_item div input").eq(0).focus()
            }, 100);
        }, 200);
    }

    function init() {
        //开启沉静式
        var header = $api.dom('.hd');
        if (header) {
            $api.fixStatusBar(header);
        }
    } //endinit
    var app = new Vue({
        el: '#app',
        data: {
            changeQuantityMask: false, // 是否显示遮罩
            lackDrugsMask: false, // 缺药提示
            specialDrugsMask: false, //特殊药材签字确认
            alwaysUsedPlanMask: false, //常用方遮罩
            radioCheched: false, // 单选框选择确认
            searchKey: "", // 搜索关键词
            num: 1,
            searchReslut: [], // 搜索出来的药材数组
            allDrugs: [], // 总共的药材
            allDrugsNum: 0, // 全部药材共多少g
            stringAllDrugs: [], // 全部药材的string类型
            noticeTip: "",
            checkDrugsMask: false,
            title: "", //常用方名称
            drugMoney: 0.000,
        },
        methods: {
            toThreeDecimal: function (val) {
                return $api.toThreeDecimal(val)
            },
            created: function () {
                var $this = this;
                this.drugMoney = 0
                if (api.pageParam.allDrugs) {
                    this.allDrugs = api.pageParam.allDrugs
                    this.allDrugsNum = 0 // 每次计算数量时都需要先置空
                    for (var i = 0; i < this.allDrugs.length; i++) {
                        this.allDrugsNum += Number(this.allDrugs[i].quantity)
                        this.drugMoney += (Number(this.allDrugs[i].quantity) * Number(this.allDrugs[i]
                            .salePrice))
                    }
                }
                api.addEventListener({
                    name: 'alwaysUsedPlan'
                }, function (ret, err) {
                    $this.allDrugs = ret.value.value
                    $this.sendData()
                });
                api.addEventListener({
                    name: 'checkDrugsMask'
                }, function (ret, err) {
                    $this.checkDrugs()
                });
            },
            checkDrugs() {
                app.checkDrugsMask = true
            },
            saveDrugs: function () {
                this.allDrugsNum = 0;
                this.drugMoney = 0;
                for (var i = 0; i < this.allDrugs.length; i++) {
                    this.allDrugsNum += Number(this.allDrugs[i].quantity)
                    this.drugMoney += (Number(this.allDrugs[i].quantity) * Number(this.allDrugs[i]
                        .salePrice))
                }
                api.sendEvent({
                    name: 'broadcast-drugs',
                    extra: {
                        allDrugs: this.allDrugs,
                        drugMoney: this.drugMoney
                    }
                });
                toast("保存成功")
                setTimeout(function () {
                    api.closeWin()
                }, 500);
            },
            // 发送数据
            sendData: function (val) {
                this.allDrugsNum = 0 // 每次计算数量时都需要先置空
                this.drugMoney = 0
                for (var i = 0; i < this.allDrugs.length; i++) {
                    this.allDrugsNum += Number(this.allDrugs[i].quantity)
                    this.drugMoney += (Number(this.allDrugs[i].quantity) * Number(this.allDrugs[i]
                        .salePrice))
                }
                this.noticeTip = "请确认当前共" + this.allDrugs.length + "味药材,共" + this.allDrugsNum + "g"

                // 发送数据给win
                api.sendEvent({
                    name: 'allDrugs',
                    extra: {
                        allDrugs: this.allDrugs,
                        drugMoney: this.drugMoney
                    }
                });
            },
            // 按倍改量
            delNum: function () {
                if (this.num == 0 || this.num < 0) {
                    this.num = 0
                } else {
                    this.num--
                }
            },
            addNum: function () {
                this.num++
            },
            pushAllDrugs: function (name, drugsNo, salePrice, specs, storeId, drugsId) { // 往总药材数组中添加数据
                var item = {
                    userId: $api.getStorage("emp").userId,
                    name: name,
                    storeId: storeId,
                    drugsNo: drugsNo,
                    salePrice: salePrice,
                    quantity: "",
                    unit: "g",
                    specs: specs,
                    remark: "无备注",
                    drugs_id: drugsId,
                }
                this.allDrugs.unshift(item)
                this.searchKey = ""
            },
            delAllDrugs: function (index) { // 在总药材数组中删除指定下标数据
                this.allDrugs.splice(index, 1)
                this.sendData()
            },
            // 清空药材
            emptyDrugs: function () {
                var $this = this;
                api.confirm({
                    title: '清空药材',
                    msg: '确定清空全部药材吗?',
                    buttons: ['确定', '取消']
                }, function (ret, err) {
                    var index = ret.buttonIndex;
                    if (index == 1) {
                        $this.allDrugs = []
                        $this.allDrugsNum = 0
                        $this.drugMoney = 0
                        // 发送数据给win
                        api.sendEvent({
                            name: 'allDrugs',
                            extra: {
                                allDrugs: $this.allDrugs,
                                drugMoney: $this.drugMoney
                            }
                        });
                        toast("全部清除成功")
                    } else {
                        toast("取消清除")
                    }

                });
            }, //end emptyDrugs
            alwaysUsedMask: function () {
                this.alwaysUsedPlanMask = true
            },
            saveAlwaysUsedPlan: function () {
                var $this = this;
                if ($this.title == '') {
                    api.toast({
                        msg: '请填写常用方名称！',
                        duration: 2000,
                        location: 'middle'
                    });
                    return;
                }
                if ($this.allDrugs.length == 0) {
                    api.toast({
                        msg: '您没有输入药材！',
                        duration: 2000,
                        location: 'middle'
                    });
                    return;
                }
                post_ajax("doctor/frequent/save", {
                    userId: $api.getStorage("emp").userId,
                    name: this.title,
                    remark: String(this.stringAllDrugs),
                    frequentItemDtoList: $this.allDrugs,
                }, function (ret, err) {
                    alert(JSON.stringify(ret))
                    alert(JSON.stringify(err))
                    if (ret.code == 2000) {
                        $this.alwaysUsedPlanMask = false
                        toast("保存成功")
                        return
                    } else {
                        api.alert("保存失败，请检查您输入的是否正确")
                        return
                    }
                })
            } //endsaveAlwaysUsedPlan
        },
        watch: {
            num: function (val) {
                if (val < 0) {
                    this.num = 0
                }
            },
            searchKey: function (val) {
                var $this = this;
                api.showProgress({
                    style: 'default',
                    animationType: 'fade',
                    title: '查询中...',
                    text: '请稍等...',
                    modal: true
                });
                api.ajax({
                    headers: {
                        "token": $api.getStorage("token")
                    }, //传送token
                    url: ROOTHTTP + "doctor/list/search/drugs/page",
                    method: 'GET',
                    timeout: 100,
                    dataType: 'json',
                    data: {
                        values: {
                            storeId: api.pageParam.storeId ? api.pageParam.storeId : 0,
                            name: val,
                            page: 1,
                            pagesize: 10,
                        }
                    },
                    contentType: "application/json"
                }, function (ret, err) {
                    if (ret.code == 2000) {
                        $this.searchReslut = ret.data.data
                    } //endif
                    api.hideProgress();
                }); //endajax
                this.num = 1
                this.noticeTip = "请确认当前共" + this.allDrugs.length + "味药材,共" + this.allDrugsNum + "g"
            },
            allDrugs: function (val) {
                this.noticeTip = "请确认当前共" + this.allDrugs.length + "味药材,共" + this.allDrugsNum + "g"
            }
        },
    }) //endvue
</script>